package com.kaifamiao.servlet;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

@WebServlet( "/sign/in" )
public class SignInServlet extends HttpServlet {

    @Override
    protected void doPost(HttpServletRequest request , HttpServletResponse response)
            throws ServletException, IOException {
        String uname = request.getParameter( "username" );
        String pwd = request.getParameter( "password" );
        if( "jiangyuzhi".equals( uname ) && "hello".equals( pwd ) ){
            // request.setAttribute( "username" , uname );
            HttpSession session = request.getSession();
            session.setAttribute( "username" , uname );
            RequestDispatcher dispatcher = request.getRequestDispatcher( "/WEB-INF/main.jsp" );
            dispatcher.forward( request , response );
            return ;
        }

        response.sendRedirect( "/index.html" );
    }

}
